package web;

import com.fasterxml.jackson.databind.ObjectMapper;
import pojo.User;
import service.UserService;
import service.impl.UserServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/user")
public class UserServlet extends BaseServlet{

    private UserService userService = new UserServiceImpl();

    private ObjectMapper om = new ObjectMapper();

    private void findAll(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        //接收参数
        //调用service
        List<User> userList = userService.findAll();

        //将userList转成json字符串，写回到浏览器
        String json = om.writeValueAsString(userList);

        resp.getWriter().write(json);
    }
}
